function y = resolve(htio)
% transio::resolve  - given entire contents in good dims
%
% FORMAT:       y = resolve(tio);
%
% Input fields:
%
%       tio         transio object
%
% Output fields:
%
%       y           data retrieved from transio object

% Version:  v0.7b
% Build:    7090614
% Date:     Sep-06 2007, 2:54 PM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
    numel(struct(htio)) ~= 1
    error( ...
        'transio:BadSubsRef', ...
        'No S subsref struct given.' ...
    );
end

% try retrieval
try
    fid = 0;
    if htio.LittleND
        fid = fopen(htio.FileName, 'rb', 'ieee-le');
    else
        fid = fopen(htio.FileName, 'rb', 'ieee-be');
    end
    if fid < 1
        error('FILE_NOT_OPEN');
    end
    fseek(fid, htio.IOOffset, -1);
    if ftell(fid) ~= htio.IOOffset
        error('FILE_SEEK_ERROR');
    end
    y = reshape(fread(fid, ...
        [prod(htio.DataDims), 1], ['*' htio.DataType]), htio.DataDims);
    fclose(fid);
    fid = 0;
catch
    if fid > 0
        fclose(fid);
    end
    error( ...
        'transio:FileReadError', ...
        'Error opening file / reading contens.' ...
    );
end
